#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=198 lang=cpp
 *
 * [198] 打家劫舍
 */

// @lc code=start
class Solution {
public:
    // 偷i dp[i] = max(dp[i - 2]) + m[i];   
    int rob(vector<int>& nums) {
        if (nums.size() == 1) return nums[0];
        else if (nums.size() == 2) return max(nums[0], nums[1]);
        int beforebefore = nums[0], before = nums[1];
        for (int i = 2; i < nums.size(); i++) {
            int t = before; 
            before = beforebefore + nums[i];
            beforebefore = max(t, beforebefore);
        }
        return max(before, beforebefore);
    }
};
// @lc code=end

